package com.px.device.controller;

import com.px.common.annotation.Log;
import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.core.page.TableDataInfo;
import com.px.common.enums.BusinessType;
import com.px.common.utils.poi.ExcelUtil;
import com.px.device.domain.RoutesInfo;
import com.px.device.domain.RoutesVo;
import com.px.device.service.IRoutesInfoService;
import com.px.framework.aes.AesSecurityParameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 航线基础信息Controller
 * 
 * @author WRJ
 * @date 2024-08
 */
@Api("航线基础信息")
@RestController
@RequestMapping("/routes/info")
public class RoutesInfoController extends BaseController
{
    @Autowired
    private IRoutesInfoService routesInfoService;

    /**
     * 查询航线基础信息列表
     */
    @ApiOperation("查询机场航线基础信息列表")
    @PreAuthorize("@ss.hasPermi('routes:info:list')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(RoutesInfo routesInfo)
    {
        startPage();
        List<RoutesInfo> list = routesInfoService.selectRoutesInfoList(routesInfo);
        return getDataTable(list);
    }

    @ApiOperation("查询航线基础信息列表")
    @PreAuthorize("@ss.hasPermi('notroutes:info:list')")
    @GetMapping("/notAirportList")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo notAirportList(RoutesInfo routesInfo)
    {
        startPage();
        List<RoutesInfo> list = routesInfoService.selectRoutesInfoListNotAirport(routesInfo);
        return getDataTable(list);
    }


    /**
     * 导出航线基础信息列表
     */
    @ApiOperation("导出航线基础信息列表")
    @PreAuthorize("@ss.hasPermi('routes:info:export')")
    @Log(title = "航线基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AesSecurityParameter
    public void export(HttpServletResponse response, RoutesInfo routesInfo)
    {
        List<RoutesInfo> list = routesInfoService.selectRoutesInfoList(routesInfo);
        ExcelUtil<RoutesInfo> util = new ExcelUtil<RoutesInfo>(RoutesInfo.class);
        util.exportExcel(response, list, "航线基础信息数据");
    }

    /**
     * 获取航线基础信息详细信息
     */
    @ApiOperation("获取航线基础信息详细信息")
    @PreAuthorize("@ss.hasPermi('routes:info:query')")
    @GetMapping(value = "/{routesId}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("routesId") Long routesId)
    {
        return success(routesInfoService.selectRoutesInfoByRoutesId(routesId));
    }

    /**
     * 新增航线基础信息
     */
    @ApiOperation("新增航线基础信息")
    @PreAuthorize("@ss.hasPermi('routes:info:edit')")
    @Log(title = "航线基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult add(@RequestBody RoutesVo routesVo) throws Exception {
        routesVo.routesInfo.setCreateBy(getUsername());
        return toAjax(routesInfoService.insertRoutesInfo(routesVo));
    }

    /**
     * 新增航线基础信息
     */
    @ApiOperation("新增航线基础信息")
    @PreAuthorize("@ss.hasPermi('notroutes:info:add')")
    @Log(title = "航线基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/notAirport")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult notAdd(@RequestBody RoutesVo routesVo) throws Exception {
        routesVo.routesInfo.setCreateBy(getUsername());
        return toAjax(routesInfoService.insertRoutesInfo(routesVo));
    }

    /**
     * 修改航线基础信息
     */
    @ApiOperation("修改航线基础信息")
    @PreAuthorize("@ss.hasPermi('routes:info:edit')")
    @Log(title = "航线基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult edit(@RequestBody RoutesVo routesVo) throws Exception {
        routesVo.routesInfo.setUpdateBy(getUsername() + "");

        return toAjax(routesInfoService.updateRoutesInfo(routesVo));
    }

    /**
     * 修改航线基础信息
     */
    @ApiOperation("修改航线基础信息")
    @PreAuthorize("@ss.hasPermi('notroutes:info:edit')")
    @Log(title = "航线基础信息", businessType = BusinessType.UPDATE)
    @PutMapping("/notAirport")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult notEdit(@RequestBody RoutesVo routesVo) throws Exception {
        routesVo.routesInfo.setUpdateBy(getUsername() + "");

        return toAjax(routesInfoService.updateRoutesInfo(routesVo));
    }

    /**
     * 删除航线基础信息
     */
    @ApiOperation("删除航线基础信息")
    @PreAuthorize("@ss.hasPermi('routes:info:remove')")
    @Log(title = "航线基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{routesIds}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult remove(@PathVariable Long[] routesIds)
    {
        return toAjax(routesInfoService.deleteRoutesInfoByRoutesIds(routesIds));
    }

    /**
     * 删除航线基础信息
     */
    @ApiOperation("删除航线基础信息")
    @PreAuthorize("@ss.hasPermi('notroutes:info:remove')")
    @Log(title = "航线基础信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/notAirport/{routesIds}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult NotRemove(@PathVariable Long[] routesIds)
    {
        return toAjax(routesInfoService.deleteRoutesInfoByRoutesIds(routesIds));
    }
}
